//
//  HNSH_ConfirmOrderGoodsFooter.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/26.
//

#import "HNSH_ConfirmOrderGoodsFooter.h"

@interface HNSH_ConfirmOrderGoodsFooter ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;

/* totalLabel */
@property (nonatomic, strong) UILabel *totalLabel;
/* 小计 */
@property (nonatomic, strong) UILabel *xjLabel;
/* 可得积分 */
@property (nonatomic, strong) UILabel *kdjfLabel;

/* remarkBgView */
@property (nonatomic, strong) UIView *remarkBgView;
/* remarkTitleLabel */
@property (nonatomic, strong) UILabel *remarkTitleLabel;
/* remarkField */
@property (nonatomic, strong) UITextField *remarkField;

@end

@implementation HNSH_ConfirmOrderGoodsFooter

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_ConfirmOrderModel *)model {
    _model = model;
    self.totalLabel.text = model.summary_text;
//    NSAttributedString * attString = [[NSAttributedString alloc] initWithData:[model.summary_price_text dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    self.xjLabel.text = [NSString stringWithFormat:@"小计：%@",model.summary_price_text];
    self.xjLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.xjLabel.text SelectContent:@"小计：" CommonFont:self.xjLabel.font SpeFont:[UIFont systemFontOfSize:12] Color:[UIColor appGrayLabelColor]];;
    
//    NSAttributedString * attString1 = [[NSAttributedString alloc] initWithData:[model.total_reward_amount dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    
    self.kdjfLabel.hidden = [model.total_reward_amount doubleValue] <= 0;
    self.kdjfLabel.text = [NSString stringWithFormat:@"可得购物值：%@",model.total_reward_amount];
    self.kdjfLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.kdjfLabel.text SelectContent:@"可得购物值：" CommonFont:self.kdjfLabel.font SpeFont:[UIFont systemFontOfSize:12] Color:[UIColor appGrayLabelColor]];
}

- (void)configUI {
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.remarkBgView];
    [self.remarkBgView addSubview:self.remarkTitleLabel];
    [self.remarkBgView addSubview:self.remarkField];
    
    [self.bgView addSubview:self.kdjfLabel];
    [self.bgView addSubview:self.xjLabel];
    [self.bgView addSubview:self.totalLabel];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-8);
    }];
    
    [self.remarkBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(8);
        make.height.mas_equalTo(44);
    }];
    
    [self.remarkTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.top.bottom.equalTo(self.remarkBgView);
    }];
    
    [self.remarkField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.remarkTitleLabel.mas_right).offset(12);
        make.width.mas_equalTo(kScreenWidth-130);
        make.top.bottom.equalTo(self.remarkBgView);
    }];
    
    [self.kdjfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-22);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(22);
    }];
    
    [self.xjLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.kdjfLabel.mas_top).offset(-9);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(22);
    }];
    
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.xjLabel.mas_top).offset(-9);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(17);
    }];
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
    }
    return _bgView;
}

- (UIView *)remarkBgView {
    if (!_remarkBgView) {
        _remarkBgView = [[UIView alloc]init];
        _remarkBgView.backgroundColor = [UIColor appBGColor];
        _remarkBgView.layer.cornerRadius = 8;
        _remarkBgView.layer.masksToBounds = YES;
    }
    return _remarkBgView;
}

- (UILabel *)remarkTitleLabel {
    if (!_remarkTitleLabel) {
        _remarkTitleLabel = [[UILabel alloc]init];
        _remarkTitleLabel.text = @"商品备注";
        _remarkTitleLabel.textColor = [UIColor appBlackLabelColor];
        _remarkTitleLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _remarkTitleLabel;
}

- (UITextField *)remarkField {
    if (!_remarkField) {
        _remarkField = [UITextField new];
        _remarkField.backgroundColor = [UIColor clearColor];
        _remarkField.textColor = [UIColor appBlackLabelColor];
        _remarkField.font = [UIFont systemFontOfSize:14];
        _remarkField.enablesReturnKeyAutomatically = YES;
        _remarkField.placeholder = @"选填：填写留言";
        NSMutableDictionary * attDic = [@{NSForegroundColorAttributeName:[UIColor appGrayLabelColor], NSFontAttributeName:_remarkField.font} mutableCopy];
        NSMutableAttributedString * attPlace = [[NSMutableAttributedString alloc] initWithString:_remarkField.placeholder attributes:attDic];
        _remarkField.attributedPlaceholder = attPlace;
        WeakSelf(weakSelf);
        [[_remarkField rac_signalForControlEvents:UIControlEventEditingChanged] subscribeNext:^(__kindof UIControl * _Nullable x) {
            UITextField *field = x;
            if (weakSelf.footerBlock) {
                weakSelf.footerBlock(field.text);
            }
        }];
    }
    return _remarkField;
}

- (UILabel *)totalLabel {
    if (!_totalLabel) {
        _totalLabel = [[UILabel alloc]init];
        _totalLabel.text = @"";
        _totalLabel.textColor = [UIColor appGrayLabelColor];
        _totalLabel.font = [UIFont systemFontOfSize:12];
    }
    return _totalLabel;
}

- (UILabel *)xjLabel {
    if (!_xjLabel) {
        _xjLabel = [[UILabel alloc]init];
        _xjLabel.text = @"";
        _xjLabel.textColor = [UIColor appGreenColor];
        _xjLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _xjLabel;
}

- (UILabel *)kdjfLabel {
    if (!_kdjfLabel) {
        _kdjfLabel = [[UILabel alloc]init];
        _kdjfLabel.text = @"";
        _kdjfLabel.textColor = [UIColor appGreenColor];
        _kdjfLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _kdjfLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
